//
//  network_filter_base.cpp
//  testpcap
//
//  Created by bugforever on 1/10/15.
//  Copyright (c) 2015 bugforever. All rights reserved.
//

#include "network_filter_base.h"
#include "assert.h"

network_filter_base::network_filter_base( FILTER_ACCEPT_DATATYPE input_type , FILTER_ACCEPT_DATATYPE output_type )
: m_input_type(input_type)
, m_output_type( output_type )
{
    ;
}

network_filter_base::~network_filter_base()
{
    ;
}

bool network_filter_base::set_network_filter( interface_network_filter * ptr_obj )
{
    if( !ptr_obj )
        return false;
    
    assert( ptr_obj->get_filter_accept_datatype() == get_filter_output_datatype() );
    
    m_ptr_filter = ptr_obj;
    
    return true;
}

bool network_filter_base::set_parent_network_filter( interface_network_filter * ptr_obj )
{
    if( !ptr_obj )
        return false;
    
    assert( ptr_obj->get_filter_output_datatype() == get_filter_accept_datatype() );
    
    m_ptr_parent = ptr_obj;
    
    return true;
}

void network_filter_base::set_event_callback( interface_event_callback * ptr_obj )
{
    m_ptr_event = ptr_obj;
}

void network_filter_base::send_network_data( FILTER_ACCEPT_DATATYPE type , void * ptr_data )
{
    assert( type == get_filter_output_datatype() );
    
    if( m_ptr_filter )
        m_ptr_filter->recv_network_data(type, ptr_data);
}

void network_filter_base::recv_network_data( FILTER_ACCEPT_DATATYPE type , void * ptr_data )
{
    assert( type == get_filter_accept_datatype() );
    
    process_network_data( type , ptr_data );
}

FILTER_ACCEPT_DATATYPE network_filter_base::get_filter_accept_datatype()
{
    return m_input_type;
}

FILTER_ACCEPT_DATATYPE network_filter_base::get_filter_output_datatype()
{
    return m_output_type;
}

void network_filter_base::send_event( int event_type , char * str_event , void * param1 , void * param2 )
{
    if( m_ptr_event )
        m_ptr_event->on_event(event_type, str_event, param1, param2);
}








